package cn.cl.gulimall.product.controller;

import java.util.Arrays;
import java.util.Map;

import cn.cl.common.valid.AddGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import cn.cl.gulimall.product.entity.BrandEntity;
import cn.cl.gulimall.product.service.BrandService;
import cn.cl.common.utils.PageUtils;
import cn.cl.common.utils.R;



/**
 * 品牌
 *
 * @author 高志红
 * @email 1739745826@qq.com
 * @date 2020-05-07 19:59:24
 */
@RestController
@RequestMapping("product/brand")
public class BrandController {
	@Autowired
	private BrandService brandService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = brandService.queryPage(params);
		return R.ok().put("page", page);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{brandId}")
	public R info(@PathVariable("brandId") Long brandId) {
		BrandEntity brand = brandService.getById(brandId);

		return R.ok().put("brand", brand);
	}

	/**
	 * 保存
	 */
	@PostMapping("/save")
	public R save(@Validated(AddGroup.class) @RequestBody BrandEntity brand) {
		brandService.save(brand);
		return R.ok();
	}

	/**
	 * 品牌级联更新
	 */
	@RequestMapping("/update")
	public R update(@RequestBody BrandEntity brand) {
		brandService.updateDatail(brand);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] brandIds) {
		brandService.removeByIds(Arrays.asList(brandIds));

		return R.ok();
	}

}
